// 导入需要的config和request
import confing from '../../config/config.js';
import request from '../../util/request.js';


// 申明请求对象
const itemtypeRequest = {
    // itemtype请求的基本url
    BASE_URL: confing.SYS_URL + "/workstation",
    list(page = 1, limit = 10, workstation, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if (workstation) {
            if (workstation.workstationCode) {
                url += "&workstationCode=" + workstation.workstationCode;
            }
            if (workstation.workstationName) {
                url += "&workstationName=" + workstation.workstationName;
            }
            if (workstation.workshopName) {
                url += "&workshopName=" + workstation.workshopName;
            }
            if (workstation.processName) {
                url += "&processName=" + workstation.processName;
            }

        }
        // 发送请求
        request.get(url, callbcak);
    },

    /**
* 保存工作站
* @param {*} workstation  工作站对象
* @param {*} callback  回调函数
*/
    saveWorkstation(workstation, callback) {
        let url = this.BASE_URL + "/save";
        request.post(url, workstation, callback);
    },



    /**
 * 根据id加载工作站信息
 * @param {*} workstationId 工作站编号
 * @param {*} callback 回调函数
 */
    get(workstationId, callback) {
        if (workstationId) {
            // 准备url
            let url = this.BASE_URL + "/get?workstationId=" + workstationId;
            request.get(url, callback);
        }
        // 如果没有workstationId，不做任何处理
    },
    /**
 * 根据ID编辑工作站信息
 * @param {} workstation 
 * @param {*} callback  
 */
    edit(workstation, callback) {
        if (workstation != undefined && workstation.workstationId != undefined) {
            request.put(this.BASE_URL + "/update", workstation, callback);
        }
    },

    /**
* 根据ID删除工作站
* @param {*} workstationId 
* @param {*} callback 
*/
    delete(workstationId, callback) {
        request.delete(this.BASE_URL + "/" + workstationId, callback);
    },

        /**
     * 根据ID批量删除工作站,url的遍历,和后端没关系
     * @param {*} workstationIds
     * @param {*} callback 
     */
        deleteSelect(workstationIds, callback) {
            // 拼接URL
            let url = this.BASE_URL + "/deletes?t=1";
            if (workstationIds != undefined) {
                workstationIds.forEach(workstationId => {
                    url += "&workstationId=" + workstationId;
                });//看这个字段&workstationId=:
                request.delete(url, callback);
            }
        },
    


}
// 将itemtypeRequest暴漏出去
export default itemtypeRequest;